using System;

namespace Atomic.Libraries.Jobs
{
	[Serializable]
	public class JobResources
	{
		public JobResources()
			: this(1)
		{
		}

		public JobResources(int nodes)
			: this(nodes, 1)
		{
		}

		public JobResources(int nodes, int processorsPerNode)
		{
			if (nodes < 1 || processorsPerNode < 1)
			{
				throw new ArgumentException();
			}

			Nodes = nodes;
			ProcessorsPerNode = processorsPerNode;
		}

		public JobResources(TimeSpan time)
			: this(time, 1)
		{
			// Use e.g. TimeSpan.FromHours(1.0).
		}

		public JobResources(TimeSpan time, int nodes)
			: this(time, nodes, 1)
		{
		}

		public JobResources(TimeSpan time, int nodes, int processorsPerNode)
			: this(nodes, processorsPerNode)
		{
			if (time.Ticks < 0)
			{
				throw new ArgumentException();
			}

			Time = time;
		}

		public JobResources(TimeSpan time, int nodes, int processorsPerNode, int memoryPerProcessor)
			: this(time, nodes, processorsPerNode)
		{
			// For example, to request 2 GB per process, you would use:
			// #PBS -l pmem=2gb
			MemoryPerProcessor = memoryPerProcessor;
		}

		public TimeSpan? Time
		{
			get;
			private set;
		}

		public int Nodes
		{
			get;
			private set;
		}

		public int ProcessorsPerNode
		{
			get;
			private set;
		}

		/// <summary>
		/// Memory per processor (GB).
		/// </summary>
		public int? MemoryPerProcessor
		{
			get;
			private set;
		}
	}
}
